package com.hubing.cloud.app.web.controller;

import com.hubing.cloud.app.web.model.ResponseBean;
import com.hubing.cloud.app.web.model.dto.ItemKeyDto;
import com.hubing.cloud.app.web.model.dto.MenuDto;
import com.hubing.cloud.app.web.model.vo.MenuVO;
import com.hubing.cloud.app.web.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 查询 - 文章菜单
     *
     * @return
     */
    @PostMapping("/query")
    public ResponseBean query() {
        List<MenuVO> list = menuService.queryMenu();
        return ResponseBean.success(list);
    }

    /**
     * 保存 - 菜单
     *
     * @return
     */
    @PostMapping("/saveMenu")
    public ResponseBean saveMenu(@RequestBody MenuDto dto) {
        menuService.addMenu(dto);
        return ResponseBean.success();
    }

    /**
     * 删除 - 菜单
     *
     * @return
     */
    @PostMapping("/deleteMenu")
    public ResponseBean deleteMenu(@RequestBody ItemKeyDto dto) {
        menuService.deleteMenu(dto.getItemKeys());
        return ResponseBean.success();
    }
}
